<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>管理员列表</title>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body style="padding: 15px">
<div>
    <button class="layui-btn" onclick="add()">添加</button>
</div>
<table class="layui-table">
    @csrf
    <thead>
    <tr>
        <th>ID</th>
        <th>用户名</th>
        <th>角色</th>
        <th>昵称</th>
        <th>手机号</th>
        <th>最后登录时间</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @foreach($admin as $item)
        <tr>
            <td>{{ $item['id'] }}</td>
            <td>{{ $item['username'] }}</td>
            <td>{{ $item['gid'] }}</td>
            <td>{{ $item['nickname'] }}</td>
            <td>{{ $item['phone'] }}</td>
            <td>{{ $item['lastlogin']?date('Y-m-d H:i:s',$item['lastlogin']):'' }}</td>
            <td>{{ $item['status']==0?'启用':'禁用' }}</td>
            <td>
                <button class="layui-btn layui-btn-xs" onclick="add({{ $item['id'] }})">编辑</button>
                <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del( {{ $item['id'] }} )">删除</button>
            </td>
        </tr>
    @endforeach
    </tbody>
</table>
<script type="text/javascript">
    layui.use(['layer'],function(){
        layer = layui.layer;
        $ = layui.jquery;
    });
    //添加管理员
    function add(aid) {
        layer.open({
            type: 2,
            title: aid>0?'修改管理员':'添加管理员',
            shadeClose: true,
            shade: 0.8,
            area: ['800px', '600px'],
            content: '/admin/admin/add?aid='+aid
        });

    }
    //删除管理员
    function del(aid) {
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['删除','取消'] //按钮
        },function(){
            var _token = $('input[name="_token"]').val();
            $.post('/admin/admin/del',{aid:aid,_token:_token},function(res){
                if(res.code>0){
                    return layer.alert(res.msg,{icon:2});
                }
                layer.msg(res.msg);
                setTimeout(function(){window.location.reload();},1000);
            },'json');
        });
    }
</script>
</body>
</html>
